package logic

import (
	"context"
	"hosp/models"

	"hosp/hosprpc/hosprpc"
	"hosp/hosprpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PatientAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPatientAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PatientAddLogic {
	return &PatientAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加
func (l *PatientAddLogic) PatientAdd(in *hosprpc.PatientAddRequest) (*hosprpc.PatientAddResponse, error) {
	// todo: add your logic here and delete this line

	patient := models.Patient{
		Name:       in.Name,
		IdCard:     in.IdCard,
		NickName:   in.NickName,
		Address:    in.Address,
		CardNumber: in.CardNumber,
		IdNumber:   in.IdNumber,
		Tel:        in.Tel,
	}

	if err := patient.PatientAdd(models.DB); err != nil {
		return nil, err
	}

	return &hosprpc.PatientAddResponse{
		PatientId: int64(patient.ID),
	}, nil
}
